<?php
/**
 * Created by PhpStorm.
 * User: admin
 * Date: 2019/11/14
 * Time: 14:18
 */

namespace app\adminapiv3\controller;


class NetworkAttack extends BaseController
{
    /**
     * @name 列表
     * @author wx
     * @date 2019/11/15 13:53
     */
    public function list($host_id)
    {
        $params['host_id'] = $host_id;

        $params['description'] = $this->filterInput('description','get');
        $params['domain_name'] = $this->filterInput('domain_name','get');
        $params['url'] = $this->filterInput('url','get');
        $params['atime'] = $this->filterInput('atime','get');
        $params['type'] = $this->filterInput('type','get');
        $params['level'] = $this->filterInput('level','get');
        $params['handle'] = $this->filterInput('handle', 'get');
        $params['src_ip'] = $this->filterInput('attack_src', 'get');
        $params['dest_ip'] = $this->filterInput('attack_dest', 'get');

        $server = new \app\adminapiv3\service\NetworkAttack();
        $list = $server->toDo('list', [$params]);

        $this->jsonOutPut($list);
    }

    /**
     * @name 列表数据
     * @author wx
     * @date 2019/11/15 13:53
     */
    public function indexData()
    {
        $server = new \app\adminapiv3\service\NetworkAttack();
        $data = $server->toDo('indexData', []);

        self::jsonOutPut($data);
    }

    /**
     * @name 设置ip白名单
     * @author wx
     * @date 2019/11/15 13:54
     */
    public function allowIp($host_id)
    {

        $id = $this->filterInput('id*','post');
        $src_ip = $this->filterInput('src_ip*','post');

        $server = new \app\adminapiv3\service\NetworkAttack();
        $server->toDo('allowIp', [$host_id, $id, $src_ip]);

        $this->jsonOutPut([],true);
        $this->Async('Hgshield', 'rules');
    }

    /**
     * @name 关闭白名单
     * @param $host_id
     * @author wx
     * @date 2020/1/3 16:22
     */
    public function closeAllowIp($host_id)
    {

        $id = $this->filterInput('id*');//id

        $server = new \app\adminapiv3\service\NetworkAttack();
        $server->toDo('closeAllowIp', [$host_id, $id]);

        $this->jsonOutPut([],true);
        $this->Async('Hgshield', 'rules');
    }

    /**
     * @name 停用规则
     * @author wx
     * @date 2019/11/15 15:52
     */
    public function close($host_id)
    {
        $id = $this->filterInput('id*','post');

        $server = new \app\adminapiv3\service\NetworkAttack();
        $server->toDo('close', [$host_id, $id]);

        $this->jsonOutPut([],true);
        $this->Async('Hgshield', 'rules');
    }

    /**
     * @name 启用规则
     * @param $host_id
     * @author wx
     * @date 2020/1/3 16:37
     */
    public function open($host_id)
    {
        $id = $this->filterInput('id*','post');

        $server = new \app\adminapiv3\service\NetworkAttack();
        $server->toDo('open', [$host_id, $id]);

        $this->jsonOutPut([],true);
        $this->Async('Hgshield', 'rules');
    }

    /**
     * @name 下载数据包
     * @author wx
     * @date 2019/11/15 16:29
     */
    public function downloadData()
    {
        $id = $this->filterInput('id*', 'post');

        $server = new \app\adminapiv3\service\NetworkAttack();
        $data = $server->toDo('downloadData', [$id]);

        $this->jsonOutPut($data);
    }
}